﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace Microsoft.SPF.UI.WebParts
{
    public class HistogramRangeRefinementControl : Microsoft.SPF.UI.WebControls.HistogramRangeRefinementControl
    {
        public HistogramRangeRefinementControl()
        {
            base.RangeChartControl = new Microsoft.Office.Server.WebControls.Chart();
        }

        public void DoPrep()
        {
            OnInit(new EventArgs());
            this.EnsureChildControls();
            OnPreRender(new EventArgs());
        }

        protected override void RegisterScript()
        {

            System.Web.UI.ScriptManager.RegisterClientScriptResource(
                Page, typeof(Microsoft.SPF.UI.WebControls.HistogramRangeRefinementControl), "Microsoft.SPF.UI.WebControls.js.sliders_engine.js");

            System.Web.UI.ScriptManager.RegisterClientScriptResource(
                Page, typeof(Microsoft.SPF.UI.WebParts.HistogramRangeRefinementControl), "Microsoft.SPF.UI.WebParts.EnhancedRefinementWebPart.js.RangeSubmit.js");

            String StartScript = BuildStartupScript();
            
            System.Web.UI.ScriptManager.RegisterStartupScript(Page,
                typeof(Microsoft.SPF.UI.WebControls.HistogramRangeRefinementControl),
                "HistogramRangeRefinementStartup_" + ClientID,
                StartScript, true);

        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            //リファイナーの"リセット"および"適用"リンクの作成
            LiteralControl button = new LiteralControl();
            button.Text = "<div class=\"bref_b\"><br/><div class=\"resetButton\" onclick=\"resetRangeRefinement('" + ManagedPropertyName + "')\">リセット</div> <div class=\"applyButton\" onclick=\"applyRangeRefinement('" + ManagedPropertyName + "', " + SliderInstanceName + ");\">適用</div></div>";
            Controls.Add(button);
        }
    }
}
